<?php
namespace Admin\Controller;

use Think\Controller;

class OperateController extends CommenController{
    /**
     * 渠道列表
     */
    public function cpa_list(){
        $channel_db=M('channel','','XYC');
        $where = MycommonController::set_where(['state'], [], '');
        if(empty($where['state'])){
            $where['state']=['gt',0];
        }
        $where['shop_identifier']=$_SESSION['shop_identifier'];
        $tol = $channel_db->WHERE($where)->COUNT();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $channel_db->WHERE($where)->FIELD("id")->LIMIT($page->listfirst, $page->listRows)->ORDER("id desc")->SELECT();
        $list = array_column($list, 'id');
        $list = $channel_db->WHERE(['c.id' => ['in', $list]])->join('c left join shop_style ss on c.style_id=ss.id')->field('ss.title,c.shop_identifier,c.chan_id,c.channel_name,c.link,c.code_picture,c.state,c.ctime,c.remark,c.id,c.style_id,c.shop_id,c.lender_id,c.flow_price')->ORDER("c.state desc")->SELECT();

        $lender=M('lender','','XYC')->where(['id'=>['in',array_column($list,'lender_id')]])->getfield('id,name',true);
        foreach ($list as $k => $v) {
            $list[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
            $list[$k]['lender'] = $lender[$v['lender_id']];
        }
        $this->shop_style=json_encode(M('shop_style','','XYC')->where(['shop_identifier'=>$_SESSION['shop_identifier'],'status'=>2])->field('id,title')->select());
        $this->shopkeeper=json_encode(M('shopkeeper','','XYC')->join('sk left join shopkeeper_role sr on sr.sid=sk.id')->join('left join communication c on sk.id=c.shop_id')->where(['sk.shop_idenfier'=>$_SESSION['shop_identifier'],'sk.state'=>1,'sr.rid'=>10,'(case when c.qq!="" or c.wx!="" then 1 else 0 end)'=>['egt',0]])->field('sk.id,c.nickname as name')->select());
//        $this->service_market=json_encode(M('service_binding','','XYC_SERVICE')->join('sb left join service_market sm on sb.server_id=sm.id')->where(['sb.shop_identifier'=>$_SESSION['shop_identifier'],'sb.status'=>2,'sm.status'=>1,])->field('sm.id,sm.name')->select());
        $this->lender=json_encode(M('lender','','XYC')->where(['shop_idenfier'=>$_SESSION['shop_identifier'],'is_delete'=>1])->field('id,name')->select());
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol
        ));
        $this->display();
    }
    /**
     * 添加或修改
     */
    public function cpa_edit(){
        if(IS_POST) {
            $data = I('post.');
            $id = $data['chan_id'];
            if (empty($data['chan_id'])) {
                $data['chan_id'] = md5(time() . rand(1000000, 999999));
                $data['shop_identifier'] = $_SESSION['shop_identifier'];
                $code_picture = './Public/upload/' . $data['chan_id'] . '.png';
                Vendor('phpqrcode.phpqrcode');
                //生成二维码图片
                $object = new \QRcode();
                $data['link'] = 'https://nxyc.dstlkj.com/Account/login_attestation?channelNum=' . $data['chan_id'] . '&shopIdentifier=' . $data['shop_identifier'];//网址或者是文本内容
                $level = 3;
                $size = 4;
                $errorCorrectionLevel = intval($level);//容错级别
                $matrixPointSize = intval($size);//生成图片大小
                $object->png($data['link'], $code_picture, $errorCorrectionLevel, $matrixPointSize, 2);
                $data['code_picture'] = MycommonController::addossimg($code_picture);
                if (!$data['code_picture']) {
                    MycommonController::ajax('1002', '图片上传失败');
                }
                $data['ctime'] = time();
            }
            $ret = $this->edit(M('channel', '', 'XYC'), ['chan_id' => $id], $id, $data);
            if($ret==1){
                if(empty($id)){
                    $content= '在【商户后台-运营管理-渠道列表】添加渠道【'. $data['channel_name'].'】';
                }else{
                    $channel_name=M('channel', '', 'XYC')->where(['chan_id' => $id])->getfield('channel_name');
                    if($channel_name==$data['channel_name']){
                        $content= '在【商户后台-运营管理-渠道列表】修改渠道【'.$channel_name.'】';
                    }else{
                        $content= '在【商户后台-运营管理-渠道列表】修改渠道【'.$channel_name.'】为【'. $data['channel_name'].'】';
                    }
                }
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],$content,3);
                MycommonController::ajax('1001', '编辑成功');
            }else{
                MycommonController::ajax('1002', '编辑失败');
            }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }
    }

    /**
     * 假删除
     */
    public function delcpa(){
        if(IS_POST){
        $id=$data['chan_id']=I('chan_id');
        $data['state']=-1;
        $ret=$this->edit(M('channel','','XYC'),['chan_id'=>$id],$id,$data);
        if($ret==1){
            $channel_name=M('channel', '', 'XYC')->where(['chan_id' => $id])->getfield('channel_name');
            add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],'在【商户后台-运营管理-渠道列表】删除渠道【'.$channel_name.'】',3);
            MycommonController::ajax('1001', '编辑成功');
        }else{
            MycommonController::ajax('1002', '编辑失败');
        }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }
    }

    public function edit($info,$where,$id,$data){
        if(empty($id)){
            if($info->add($data)){
                return 1;
            }else{
                return 2;
            }
        }else{
            if($info->where($where)->save($data)){
                return 1;
            }else{
                return 2;
            }
        }
    }

    /**
     * 营销管理
     */
    public function marketing(){
        $marketing_db=M('marketing','','XYC');
        $where = MycommonController::set_where(['state'], '', '',['mobile']);
        $where['is_delete']=1;
        $where['shop_idenfier']=$_SESSION['shop_identifier'];
        $tol = $marketing_db->WHERE($where)->COUNT();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $marketing_db->WHERE($where)->FIELD("id")->LIMIT($page->listfirst, $page->listRows)->ORDER("id desc")->SELECT();
        $list = array_column($list, 'id');
        $list = $marketing_db->WHERE(['id' => ['in', $list]])->field('shop_idenfier,is_delete',true)->ORDER("id desc")->SELECT();
        foreach ($list as $k => $v) {
            $list[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
           /* $list[$k]['name']= MycommonController::hidestr($v['name'],0,-1);
            $list[$k]['mobile']= MycommonController::hidestr($v['mobile'],3,4);*/
        }
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol
        ));

        $this->display();
    }
    /**
     * 编辑营销数据
     */
    public function market_edit(){
        if(IS_POST){
            $data=I('post.');
            $id=$data['id'];
            $ret=$this->edit(M('marketing','','XYC'),['id'=>$id],$id,$data);
            if($ret==1){
                $name=M('marketing', '', 'XYC')->where(['id' => $id])->getfield('name');
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],'在【商户后台-运营管理-营销管理】编辑营销数据，用户名为【'.$name.'】',3);
                MycommonController::ajax('1001', '编辑成功');
            }else{
                MycommonController::ajax('1002', '编辑失败');
            }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }
    }
    /**
     * 假删除
     */
    public function delmarket(){
        if(IS_POST){
            $id=I('id');
            $name=M('marketing', '', 'XYC')->where(['id'=>['in',$id]])->getfield('name',true);
            if(count($name)>1){
                $name=implode(",", $name);
            }else{
                $name=$name[0];
            }
            $data['is_delete']=-1;
            $ret=$this->edit(M('marketing','','XYC'),['id'=>['in',$id]],$id,$data);
            if($ret==1){
                $name=M('marketing', '', 'XYC')->where(['id'=>['in',$id]])->getfield('name',true);

                if(count($name)>1){
                    $name=implode(",", $name);
                }else{
                    $name=$name[0];
                }
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],'在【商户后台-运营管理-营销管理】删除营销数据，用户名为【'.$name.'】',3);
                MycommonController::ajax('1001', '删除成功');
            }else{
                MycommonController::ajax('1002', '删除失败');
            }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }
    }
    /**
     * 渠道账号列表
     */
    public function cpa_account_list(){
        $shopkeeper_db=M('shopkeeper','','XYC');
        $where = MycommonController::set_where(['state'], ['account','mobile','name'], '');
        if(empty($where['state'])){
            $where['state']=['neq',-1];
        }
        $where['chan_id']=['neq',''];
        $where['shop_idenfier']=$_SESSION['shop_identifier'];
        $tol = $shopkeeper_db->WHERE($where)->COUNT();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $shopkeeper_db->WHERE($where)->FIELD("id")->LIMIT($page->listfirst, $page->listRows)->ORDER("id desc")->SELECT();
        $list = array_column($list, 'id');
        $list = $shopkeeper_db->join('sk left join channel c on sk.chan_id=c.chan_id')->WHERE(['sk.id' => ['in', $list]])->ORDER("sk.id desc")->field('c.chan_id,c.channel_name,sk.account,sk.name,sk.state,sk.ctime,sk.id,sk.mobile')->SELECT();
        foreach ($list as $k => $v) {
            $list[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
        }
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol
        ));
        $this->channel=json_encode(M('channel','','XYC')->WHERE(['shop_identifier'=>$_SESSION['shop_identifier'],'state'=>2])->FIELD("id,channel_name")->SELECT());
//        $this->channel=M('channel','','XYC')->where(['shop_identifier'=>$_SESSION['shop_identifier'],'state'=>['neq',-1]])->field(['id,channel_name'])->select();

        $this->display();
    }
    /***
     * 编辑渠道账号
     */
    public function edit_cpa_account(){
        if(IS_POST){
            $info=M('shopkeeper', '', 'XYC');
            $role=M('shopkeeper_role','','XYC');
            $data=I('post.');
            $id=$data['id'];
            if(!preg_match("/1[34578]{1}\d{9}$/",$data['mobile'])){
                MycommonController::ajax('1002', '手机号码格式不正确');
            }
            if(empty($data['password'])){
                unset($data['password']);
            }else{
                if(!preg_match("/^(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{6,}/",$data['password'])){
                    MycommonController::ajax('1002', '密码必须由数字、字母、特殊字符三种中的两种组成,且不少于六位');
                }
                $pwd=md5($data['account'].'xycshop'.$data['password']);
                $data['password']=$pwd;
            }
            if(empty($id)){
                $role->startTrans();
                $info->startTrans();
                unset($data['id']);
                $data['ctime']=time();
                if(empty($data['password'])){
                    MycommonController::ajax('1002', '密码不能为空');
                }
                $count=$info->where(['account'=>$data['account']])->count();
                if($count>0){
                    MycommonController::ajax('1002', '该账号已存在');
                }
                $data['is_hide']=2;
                $data['rid']=13;
                $data['shop_idenfier']=$_SESSION['shop_identifier'];
                $merchant_name=M('merchant','','XYC')->where(['shop_identifier'=>$_SESSION['shop_identifier'],'status'=>1])->getField('merchant_name');
                if(empty($merchant_name)){
                    MycommonController::ajax('1002', '添加失败');
                }
                $data['merchant_name']=$merchant_name;
                $id=$info->add($data);
                if(empty($id)){
                    $role->rollback();
                    $info->rollback();
                    MycommonController::ajax('1002', '添加失败');
                }
                $ret1=$role->add(['shop_identifier'=>$_SESSION['shop_identifier'],'rid'=>6,'sid'=>$id]);
                if(empty($ret1)){
                    $role->rollback();
                    $info->rollback();
                    MycommonController::ajax('1002', '添加失败');
                }else{
                    $role->commit();
                    $info->commit();
                    $content= '在【商户后台-运营管理-渠道列表】添加渠道账号【'. $data['name'].'】';
                    add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],$content,3);
                    MycommonController::ajax('1001', '添加成功');
                }
            }else{
                $ret=$this->edit($info,['id'=>$id],$id,$data);
                if($ret==1){
                    $name=$info->where(['id' => $id])->getfield('name');
                    if($name==$data['name']){
                        $content= '在【商户后台-运营管理-渠道账号列表】修改渠道账号【'.$name.'】';
                    }else{
                        $content= '在【商户后台-运营管理-渠道账号列表】修改渠道账号【'.$name.'】为【'. $data['name'].'】';
                    }
                    add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],$content,3);
                    MycommonController::ajax('1001', '编辑成功');
                }else{
                    MycommonController::ajax('1002', '编辑失败');
                }
            }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }
    }
    /***
     * 删除渠道账号
     */
    public function del_cpa_account(){
        if(IS_POST){
            $id=$data['id']=I('id');
            $data['state']=-1;
            $ret=$this->edit(M('shopkeeper','','XYC'),['id'=>$id],$id,$data);
            if($ret==1){
                $name=M('shopkeeper', '', 'XYC')->where(['id' => $id])->getfield('name');
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],'在【商户后台-运营管理-渠道账号列表】删除渠道账号【'.$name.'】',3);
                MycommonController::ajax('1001', '删除成功');
            }else{
                MycommonController::ajax('1002', '删除失败');
            }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }

    }
    /**
     * 创建样式
     */
    public function create_style(){
        $style_db=M('shop_style','','XYC');
        $where = MycommonController::set_where(['status'], ['title'], '');
        if(empty($where['status'])){
            $where['status']=['neq',3];
        }
        $where['shop_identifier']=$_SESSION['shop_identifier'];
        $tol = $style_db->WHERE($where)->COUNT();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $style_db->WHERE($where)->FIELD("id")->LIMIT($page->listfirst, $page->listRows)->ORDER("id desc")->SELECT();
        $list = array_column($list, 'id');
        $list = $style_db->WHERE(['id' => ['in', $list]])->field('shop_identifier,name',true)->ORDER("id desc")->SELECT();
        foreach ($list as $k => $v) {
            $list[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
        }
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol
        ));
        $this->display();
    }
    /**
     * 编辑页
     */
    public function edit_style(){
        $this->data=M('shop_style','','XYC')->where(['id'=>I('id')])->find();
        $this->display();
    }
    /**
     * 编辑方法
     */
    public function edit_style_func(){
        if(IS_POST){
            $data=I('post.');
            $id=$data['id'];
            if(empty($id)){
                unset($data['id']);
                $data['shop_identifier']=$_SESSION['shop_identifier'];
                $data['ctime']=time();
            }else{
                if(empty($data['banner'])){
                    unset($data['banner']);
                }
            }
            $ret=$this->edit(M('shop_style','','XYC'),['id'=>$id],$id,$data);
            if($ret==1){
                if(empty($id)){
                    $content= '在【商户后台-运营管理-创建样式】添加样式【'. $data['title'].'】';
                }else{
                    $title=M('shop_style', '', 'XYC')->where(['id' => $id])->getfield('title');
                    if($title==$data['title']){
                        $content= '在【商户后台-运营管理-渠道账号列表】修改样式【'.$title.'】';
                    }else{
                        $content= '在【商户后台-运营管理-渠道账号列表】修改样式【'.$title.'】为【'. $data['title'].'】';
                    }
                }
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],$content,3);
                MycommonController::ajax('1001', '编辑成功');
            }else{
                MycommonController::ajax('1002', '编辑失败');
            }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }
    }
    /**
     * 删除样式
     */
    public function delstyle(){
        if(IS_POST) {
            $id = $data['id'] = I('id');
            $data['status'] = 3;
            $ret=$this->edit(M('shop_style','','XYC'),['id'=>$id],$id,$data);
            if($ret==1){
                $title=M('shop_style', '', 'XYC')->where(['id' => $id])->getfield('title');
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],'在【商户后台-运营管理-渠道账号列表】删除渠道【'.$title.'】',3);
                MycommonController::ajax('1001', '删除成功');
            }else{
                MycommonController::ajax('1002', '删除失败');
            }
        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }

    }
    function getsize($size, $format) {
        $p = 0;
        if ($format == 'kb') {
            $p = 1;
        } elseif ($format == 'mb') {
            $p = 2;
        } elseif ($format == 'gb') {
            $p = 3;
        }
        $size /= pow(1024, $p);
        return number_format($size, 3);
    }
    //上传banner图
    public function uploadimg(){
        $config=[
            'maxSize'=>1048576,
            'exts'=>['jpg','gif','png','jpeg'],
            'rootPath'=>'./Public/upload/',
            'savePath'=>'',
            'autoSub'=>false,
            'subName'   =>  '',
            'saveName'  =>  uniqid().date("YmdHis",time()),//uniqid().date("YmdHis",time()),
        ];
        $upload = new \Think\Upload($config);               // 实例化上传类
        // 上传单个文件
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $pic = $upload->getError();
            MycommonController::ajax('1002', $pic);
        }else{// 上传成功 获取上传文件信息
            $picName = $info['uploadimg']['savename'];
            $picSize = $info['uploadimg']['size'];
            $picTmp  = $info['uploadimg']['tmp_name'];
            $filename = './Public/upload/'.$picName;
            $size = filesize($filename);
            $size = $this->getsize($size, 'kb'); //进行单位转换
            $imgsize = getimagesize($filename);
            if($imgsize[0]==750 && $imgsize[1]==450) {
                if($size>500){
                    unlink($filename); //删除文件
                    MycommonController::ajax('1002',  '图片必须在500K以内！');
                }else{
                    $return =  MycommonController::addossimg($filename);
                    unlink($filename); //删除文件
                    if(!$return){
                        MycommonController::ajax('1002',  '上传oss出错！');
                    }else{
                        MycommonController::ajax('1001',  $return);
                    }
                }
            }else{
                unlink($filename); //删除文件
                MycommonController::ajax('1002',  '图片上传失败,大小不匹配！');
            }

        }
    }
    /**
     * 渠道统计
     */
    public function cpa_statistics(){

        //本身关联的渠道

        $channel_a=M('shopkeeper','','XYC')->where(['id'=>$_SESSION['id']])->getfield('c_id');
        $channel_arr=explode(',',$channel_a);
        $channel=M('channel','','XYC')->where(['id'=>['in',$channel_arr]])->getfield('chan_id',true);
        $time=strtotime("today");
        $where1=['egt',$time];
//        $entry=M('user_login','','XYC')->where(['shop_identifier'=>$_SESSION['shop_identifier'],'channel'=>['in',$channel],'ctime'=>$where1,''])->group('channel')->getfield('channel,count(id) as num',true);
//        $cert=M('user','','XYC')->where(['shop_identifier'=>$_SESSION['shop_identifier'],'channel'=>['in',$channel],'cert_status'=>2,'cert_time'=>$where1])->group('channel')->getfield('channel,count(id) as num',true);
//        $borrow_where=['shop_identifier'=>$_SESSION['shop_identifier'],'channel'=>['in',''],'status'=>['in','2,3,4,5,6,9'],'loan_time'=>$where1];
//        $borrow_order=M('vz_loan','','XYC')->join('a join user b on b.id=a.user_id')->where($borrow_where)->group('channel')->getfield('channel,count(id) as num',true);
//        $item=M('vz_loan','','XYC')->where($borrow_where)->group('borrower_id')->field('channel,borrower_id,1 as num')->select();
//        $borrow_user=[];
//        foreach($item as $k=>$v){
//            if(!isset($borrow_user[$v['channel']])){
//                $borrow_user[$v['channel']]=$v['num'];
//            }else{
//                $borrow_user[$v['channel']]+=$v['num'];
//            }
//        }
//        $where2 = MycommonController::set_where([''], ['','',''], 'ctime');
//        $where2['shop_identifier']=$_SESSION['shop_identifier'];
//        $where2['type']=1;
//        $statis=M('channel_statis','','XYC')->where($where2)->group('chan_id')->getfield('chan_id,sum(entry) as entry,sum(cert) as cert,sum(borrow_user) as borrow_user,sum(borrow_order) as borrow_order',true);

        $channel_db=M('channel','','XYC');
        if(empty($where['state'])){
            $where['state']=['neq',-1];
        }
        $where['shop_identifier']=$_SESSION['shop_identifier'];
        $where['id']=['in',$channel_arr];
        $tol = $channel_db->WHERE($where)->COUNT();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $channel_db->WHERE($where)->FIELD("id")->LIMIT($page->listfirst, $page->listRows)->ORDER("id desc")->SELECT();
        $list = array_column($list, 'id');
        $list = $channel_db->WHERE(['id' => ['in', $list]])->field('chan_id,channel_name')->ORDER("id desc")->SELECT();
        $s_time=strtotime(I('start'));
        $e_time=strtotime(I('end'));
        $search=['start'=>I('start'),'end'=>I('end')];

        foreach ($list as $k => $v) {
            //注册人数
            $where=[];
            $where['channel']=$v['chan_id'];
            if(I('start') && I('end')){
                $where['ctime']=['between',[$s_time,$e_time]];
            }
            $list[$k]['register']=M('user','','XYC')->where($where)->count();
           //认证人数
            $where1=[];
            $where1['channel']=$v['chan_id'];
            $where1['cert_status']=['neq',1];
            if(I('start') && I('end')) {
                $where1['cert_time'] = ['between', [$s_time, $e_time]];
            }
            $list[$k]['cert']=M('user','','XYC')->where($where1)->count();
            //借款用户数
            $where2=[];
            $where2['a.channel']=$v['chan_id'];
            $where2['b.is_success']=['eq',2];
            if(I('start') && I('end')) {
                $where2['b.ctime'] = ['between', [$s_time, $e_time]];
            }
            $list[$k]['borrow_user']= M('user','','XYC')->join('a join vz_loan b on b.user_id=a.id')->where($where2)->count('DISTINCT b.user_id');

           //借款订单数

            $list[$k]['borrow_order']= M('user','','XYC')->join('a join vz_loan b on b.user_id=a.id')->where($where2)->count();

//            $list[$k]['entry']=(empty($entry[$v['chan_id']])?0:$entry[$v['chan_id']])+(empty($statis[$v['chan_id']]['entry'])?0:$statis[$v['chan_id']]['entry']);
//            $list[$k]['cert']=(empty($cert[$v['chan_id']])?0:$cert[$v['chan_id']])+(empty($statis[$v['chan_id']]['cert'])?0:$statis[$v['chan_id']]['cert']);
//            $list[$k]['borrow_user']=(empty($borrow_user[$v['chan_id']])?0:$borrow_user[$v['chan_id']])+(empty($statis[$v['chan_id']]['borrow_user'])?0:$statis[$v['chan_id']]['borrow_user']);
//            $list[$k]['borrow_order']=(empty($borrow_order[$v['chan_id']])?0:$borrow_order[$v['chan_id']])+(empty($statis[$v['chan_id']]['borrow_order'])?0:$statis[$v['chan_id']]['borrow_order']);
        }
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'search' => $search,
            'tol' => $tol
        ));
        $this->display();
    }

    /**
     * APP链接
     */
    public function app_url(){
//        $url=M('merchant','','XYC')->where(['shop_identifier'=>$_SESSION['shop_identifier']])->field('ios_url,app_url')->find();
        $url='http://nxyc.dstlkj.com/app/download?shop_identifier='.$_SESSION['shop_identifier'];
        $this->assign(array('url'=>$url));
        $this->display();
    }

}